<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="月份">
              <a-month-picker placeholder="请输入月份" v-model="queryParam.month" style="width: 100%" @change="onChange" showTime format='YYYY-MM' valueFormat='YYYY-MM' />
            </a-form-item>
          </a-col>
         <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="团队">
              <!-- <j-select-depart placeholder="请选择所属部门" v-model="queryParam.teamId"/> -->

              <a-select placeholder="请选择部门" v-model="queryParam.teamId" allowClear @change="changeTeam">
                <a-select-option v-for="(item, i) in teamData" :key="i" :value="item.id">
                  {{ item.label }}
                </a-select-option>
              </a-select>

            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="城市">
              <!-- <j-dict-select-tag placeholder="请选择类别" v-model="queryParam.category" dictCode="teams"/> -->
              <!-- <j-d placeholder="请选择类别" v-model="queryParam.category" dictCode="teams"/> -->

              <a-select placeholder="请选择城市" v-model="queryParam.cityId" allowClear>
                <a-select-option v-for="(item, i) in cityData" :key="i" :value="item.deptId">
                  {{ item.label }}
                </a-select-option>
              </a-select>

            </a-form-item>
          </a-col>

<!--          <j-vxe-table-->
<!--            ref="vTable"-->
<!--            toolbar-->
<!--            row-number-->
<!--            row-selection-->
<!--            keep-source-->
<!--            :height="484"-->
<!--            :columns="columns"-->
<!--            :linkage-config="linkageConfig"-->
<!--          />-->

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('收支月度报表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <emp-income-modal ref="modalForm" @ok="modalFormOk"></emp-income-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import EmpIncomeModal from './modules/EmpIncomeModal'
  import {getAction} from "@api/manage";

  export default {
    name: 'EmpIncomeList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      EmpIncomeModal
    },
    data () {
      return {

        teamData: [],
        cityData: [],

        description: 'hl_emp_income管理页面',
        // 表头
        columns: [
          {
            title:'月份',
            align:"center",
            fixed:"left",
            dataIndex: 'month'
          },
         /* {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,

            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },*/
          {
            title:'账号',
            align:"center",
            fixed:"left",
            dataIndex: 'username'
          },
          {
            title:'姓名',
            align:"center",
            fixed:"left",
            dataIndex: 'realname'
          },
          {
            title:'职位',
            align:"center",
            dataIndex: 'post'
          },
          {
            title:'级别',
            align:"center",
            dataIndex: 'level'
          },
          {
            title:'所属部门',
            align:"center",
            dataIndex: 'departName'
          },
          {
            title:'城市',
            align:"center",
            dataIndex: 'cityName'
          },
          {
            title:'城市code',
            align:"center",
            dataIndex: 'cityCode'
          },
          {
            title:'城市级别',
            align:"center",
            dataIndex: 'cityLevel'
          },
          {
            title:'团队名称',
            align:"center",
            dataIndex: 'teamName'
          },
          {
            title:'薪资',
            align:"center",
            dataIndex: 'salary'
          },
          {
            title:'线索人数',
            align:"center",
            dataIndex: 'leads'
          },
          {
            title:'入职人数',
            align:"center",
            dataIndex: 'entry'
          },
          {
            title:'确权人数',
            align:"center",
            dataIndex: 'confirm'
          },
          {
            title:'营销账号',
            align:"center",
            dataIndex: 'marketAccount'
          },
          {
            title:'营销费用(系统核算)',
            align:"center",
            dataIndex: 'market'
          },
          {
            title:'营销费用(人工上报)',
            align:"center",
            dataIndex: 'marketManual'
          },
          {
            title:'办公场地(均摊)',
            align:"center",
            dataIndex: 'officeSpace'
          },
          {
            title:'办公家具(均摊)',
            align:"center",
            dataIndex: 'officeFurniture'
          },
          {
            title:'其他',
            align:"center",
            dataIndex: 'other'
          },
          {
            title:'总支出',
            align:"center",
            dataIndex: 'totalPay'
          },
          {
            title:'总收入',
            align:"center",
            dataIndex: 'totalIncome'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/emp/empIncome/list",
          delete: "/emp/empIncome/delete",
          deleteBatch: "/emp/empIncome/deleteBatch",
          exportXlsUrl: "/emp/empIncome/exportXls",
          importExcelUrl: "emp/empIncome/importExcel",

        },
        dictOptions:{},
        superFieldList:[],

        // // 联动配置
        // linkageConfig: [
        //   {requestData: this.requestData, key: 's1'},
        // ],
        // orgs:[
        //   {
        //   title: '市',
        //   key: 's2',
        //   type: JVXETypes.normal,
        //   width: '180px',
        //   placeholder: '请选择${title}',
        //   // 联动字段（即下一级的字段）
        //   linkageKey: 's3',
        //   },
        //   {
        //     title: '县/区',
        //     key: 's3',
        //     width: '180px',
        //     options: [],
        //     placeholder: '请选择${title}',
        //   }
        // ],

        // // 模拟数据
        // mockData: [
        //   {text: '北京市', value: '110000', parent: ''},
        //   {text: '天津市', value: '120000', parent: ''},
        //   {text: '河北省', value: '130000', parent: ''},
        //   {text: '上海市', value: '310000', parent: ''},
        //
        //   {text: '北京市', value: '110100', parent: '110000'},
        //   {text: '天津市市', value: '120100', parent: '120000'},
        //   {text: '石家庄市', value: '130100', parent: '130000'},
        //   {text: '唐山市', value: '130200', parent: '130000'},
        //   {text: '秦皇岛市', value: '130300', parent: '130000'},
        //   {text: '上海市', value: '310100', parent: '310000'},
        //
        //   {text: '东城区', value: '110101', parent: '110100'},
        //   {text: '西城区', value: '110102', parent: '110100'},
        //   {text: '朝阳区', value: '110105', parent: '110100'},
        //   {text: '和平区', value: '120101', parent: '120100'},
        //   {text: '河东区', value: '120102', parent: '120100'},
        //   {text: '河西区', value: '120103', parent: '120100'},
        //   {text: '黄浦区', value: '310101', parent: '310100'},
        //   {text: '徐汇区', value: '310104', parent: '310100'},
        //   {text: '长宁区', value: '310105', parent: '310100'},
        //   {text: '长安区', value: '130102', parent: '130100'},
        //   {text: '桥西区', value: '130104', parent: '130100'},
        //   {text: '新华区', value: '130105', parent: '130100'},
        //   {text: '路南区', value: '130202', parent: '130200'},
        //   {text: '路北区', value: '130203', parent: '130200'},
        //   {text: '古冶区', value: '130204', parent: '130200'},
        //   {text: '海港区', value: '130302', parent: '130300'},
        //   {text: '山海关区', value: '130303', parent: '130300'},
        //   {text: '北戴河区', value: '130304', parent: '130300'},
        // ],
      }
    },
    created() {
      this.getTeamList() // 获取团队列表
      if (this.$route.query.month) {
        this.queryParam = {
          month: this.$route.query.month || '',
          teamId: Number(this.$route.query.teamId) || '',
          cityId: Number(this.$route.query.cityId) || ''
        }
        !this.queryParam.cityId && delete this.queryParam.cityId
        this.searchQuery()
        if (this.queryParam.teamId) {
          setTimeout(() => {
            this.teamData.some(row => {
              if (row.id === this.queryParam.teamId) {
                this.cityData = row.children || []
                return true
              }
            })
          }, 500)
        }
      } else {
        this.getSuperFieldList();
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      // 改变团队
      changeTeam(val, opt) {
        this.cityData = this.teamData[opt.key].children || []
        delete this.queryParam.cityId
      },
      // 获取团队列表
      getTeamList() {
         getAction("/emp/emp_58Pay/queryRpDeptTree", {}).then((res) => {
           this.teamData = res.result || []
          })
      },

      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'month',text:'月份',dictCode:''})
        fieldList.push({type:'string',value:'username',text:'账号',dictCode:''})
        fieldList.push({type:'string',value:'realname',text:'姓名',dictCode:''})
        fieldList.push({type:'string',value:'post',text:'职位',dictCode:''})
        fieldList.push({type:'string',value:'level',text:'级别',dictCode:''})
        fieldList.push({type:'string',value:'departName',text:'所属部门',dictCode:''})
        fieldList.push({type:'string',value:'orgCode',text:'机构编码',dictCode:''})
        fieldList.push({type:'string',value:'cityName',text:'城市',dictCode:''})
        fieldList.push({type:'string',value:'cityCode',text:'城市code',dictCode:''})
        fieldList.push({type:'string',value:'cityLevel',text:'城市级别',dictCode:''})
        fieldList.push({type:'string',value:'teamName',text:'团队名称',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'salary',text:'薪资',dictCode:''})
        fieldList.push({type:'int',value:'leads',text:'线索人数',dictCode:''})
        fieldList.push({type:'int',value:'entry',text:'入职人数',dictCode:''})
        fieldList.push({type:'int',value:'confirm',text:'确权人数',dictCode:''})
        fieldList.push({type:'string',value:'marketAccount',text:'营销账号',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'market',text:'营销费用(系统核算)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'marketManual',text:'营销费用(人工上报)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'officeSpace',text:'办公场地(均摊)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'officeFurniture',text:'办公家具(均摊)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'other',text:'其他',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'totalPay',text:'总支出',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'totalIncome',text:'总收入',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        this.superFieldList = fieldList
      },

      /**
       * 模拟从后台查询数据
       */
      requestData(parent) {
        return new Promise((resolve, reject) => {
          let data = this.mockData.filter(i => i.parent === parent)
          setTimeout(() => {
            resolve(data)
          }, 500)
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>